/*
	INFORMATION_SCHEMA.VIEWS doesn't provide enough information about a view, hence the non-recommended sys tables have been used.
*/

SELECT     i_VIEWS.TABLE_CATALOG, i_VIEWS.TABLE_SCHEMA, i_VIEWS.TABLE_NAME, clmns.name AS COLUMN_NAME, 
                      CAST(ISNULL(cik.index_column_id, 0) AS bit) AS IN_PRIMARY_KEY, CAST(ISNULL
                          ((SELECT     TOP (1) 1 AS Expr1
                              FROM         sys.foreign_key_columns AS colfk
                              WHERE     (parent_column_id = clmns.column_id) AND (parent_object_id = clmns.object_id)), 0) AS bit) AS IS_FOREIGN_KEY, 
                      usrt.name AS DATA_TYPE, CAST(CASE WHEN baset.name IN (N'nchar', N'nvarchar') AND 
                      clmns.max_length <> - 1 THEN clmns.max_length / 2 ELSE clmns.max_length END AS int) AS CHARACTER_MAXIMUM_LENGTH, CAST(clmns.precision AS int)
                       AS NUMERIC_PRECISION, CAST(clmns.scale AS int) AS NUMERIC_SCALE, clmns.is_nullable AS IS_NULLABLE, clmns.is_computed AS IS_COMPUTED,
                       v.with_check_option AS CHECK_OPTION
FROM         sys.all_views AS v INNER JOIN
                      sys.all_columns AS clmns ON clmns.object_id = v.object_id INNER JOIN
                          (SELECT     OBJECT_ID(TABLE_SCHEMA + '.' + TABLE_NAME) AS Expr1, TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, VIEW_DEFINITION, 
                                                   CHECK_OPTION, IS_UPDATABLE
                            FROM          INFORMATION_SCHEMA.VIEWS) AS i_VIEWS ON v.object_id = i_VIEWS.Expr1 LEFT OUTER JOIN
                      sys.index_columns AS cik ON cik.column_id = clmns.column_id AND cik.object_id = clmns.object_id AND 0 = cik.is_included_column LEFT OUTER JOIN
                      sys.types AS usrt ON usrt.user_type_id = clmns.user_type_id LEFT OUTER JOIN
                      sys.types AS baset ON baset.user_type_id = clmns.system_type_id AND baset.user_type_id = baset.system_type_id
WHERE     (v.is_ms_shipped = 0)
ORDER BY i_VIEWS.TABLE_CATALOG, i_VIEWS.TABLE_SCHEMA, i_VIEWS.TABLE_NAME

